﻿using UnityEngine;
using log4net;
using log4net.Config;
using System.IO;
using System;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
//[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension = "LoggerConfig.xml", Watch = true)]
public class TestLoadConfig : MonoBehaviour {

    public static readonly ILog pluginlogNative;
    public static readonly ILog pluginlog;
    public static readonly ILog log;
    private const string LOG4NET_CONF_FILE_PATH = "/Log/LoggerConfig.xml";
    static TestLoadConfig() {
        string confFilePath = Application.dataPath + LOG4NET_CONF_FILE_PATH;
        Debug.Log(confFilePath);
        FileInfo fileInfo = new FileInfo(confFilePath);
        XmlConfigurator.Configure(fileInfo);

        pluginlogNative = LogManager.GetLogger(typeof(TestLoadConfig));
        pluginlog = LogManager.GetLogger("ALLLOG");
        log = new LogAdapter();
    }
}

class LogAdapter : ILog {
    bool m_IsDebugEnabled = true;
    bool m_IsErrorEnabled = true;
    bool m_IsFatalEnabled = true;
    bool m_IsInfoEnabled  = true;
    bool m_IsWarnEnabled = true;
    ILog log = LogManager.GetLogger(typeof(LogAdapter));

    public log4net.Core.ILogger Logger { get { return log.Logger; } }
    public bool IsDebugEnabled { get { return m_IsDebugEnabled; } }
    public bool IsErrorEnabled { get { return m_IsErrorEnabled; } }
    public bool IsFatalEnabled { get { return m_IsFatalEnabled; } }
    public bool IsInfoEnabled { get { return m_IsInfoEnabled; } }
    public bool IsWarnEnabled { get { return m_IsWarnEnabled; } }

    public void Debug(object message) {
        DebugUtil.Log(message);
    }

    public void Debug(object message, Exception exception) {
        DebugUtil.Log(message);
    }

    public void DebugFormat(string format, object[] args) {
        DebugUtil.LogFormat(format, args);
    }

    public void DebugFormat(string format, object arg0) {
        DebugUtil.LogFormat(format, arg0);
    }

    public void DebugFormat(string format, object arg0, object arg1) {
        DebugUtil.LogFormat(format, arg0, arg1);
    }

    public void DebugFormat(string format, object arg0, object arg1, object arg2) {
        DebugUtil.LogFormat(format, arg0, arg1, arg2);
    }

    public void DebugFormat(System.IFormatProvider provider, string format, object[] args) {
        DebugUtil.LogFormat(format, args);
    }

    public void Info(object message) {
        Debug(message);
    }

    public void Info(object message, Exception exception) {
        Debug(message, exception);
    }

    public void InfoFormat(string format, object[] args) {
        DebugFormat(format, args);
    }

    public void InfoFormat(string format, object arg0) {
        DebugFormat(format, arg0);
    }

    public void InfoFormat(string format, object arg0, object arg1) {
        DebugFormat(format, arg0, arg1);
    }

    public void InfoFormat(string format, object arg0, object arg1, object arg2) {
        DebugFormat(format, arg0, arg1, arg2);
    }

    public void InfoFormat(System.IFormatProvider provider, string format, object[] args) {
        DebugFormat(provider, format, args);
    }

    public void Warn(object message) {
        DebugUtil.LogWarning(message);
    }

    public void Warn(object message, Exception exception) {
        DebugUtil.LogWarning(message);
    }

    public void WarnFormat(string format, object[] args) {
        DebugUtil.LogWarningFormat(format, args);
    }

    public void WarnFormat(string format, object arg0) {
        DebugUtil.LogWarningFormat(format, arg0);
    }

    public void WarnFormat(string format, object arg0, object arg1) {
        DebugUtil.LogWarningFormat(format, arg0, arg1);
    }

    public void WarnFormat(string format, object arg0, object arg1, object arg2) {
        DebugUtil.LogWarningFormat(format, arg0, arg1, arg2);
    }

    public void WarnFormat(System.IFormatProvider provider, string format, object[] args) {
        DebugUtil.LogWarningFormat(format, args);
    }

    public void Error(object message) {
        DebugUtil.LogError(message);
    }

    public void Error(object message, Exception exception) {
        DebugUtil.LogError(message);
    }

    public void ErrorFormat(string format, object[] args) {
        DebugUtil.LogErrorFormat(format, args);
    }

    public void ErrorFormat(string format, object arg0) {
        DebugUtil.LogErrorFormat(format, arg0);
    }

    public void ErrorFormat(string format, object arg0, object arg1) {
        DebugUtil.LogErrorFormat(format, arg0, arg1);
    }

    public void ErrorFormat(string format, object arg0, object arg1, object arg2) {
        DebugUtil.LogErrorFormat(format, arg0, arg1, arg2);
    }

    public void ErrorFormat(System.IFormatProvider provider, string format, object[] args) {
        DebugUtil.LogErrorFormat(format, args);
    }

    public void Fatal(object message) {
        Error(message);
    }

    public void Fatal(object message, Exception exception) {
        Error(message);
    }

    public void FatalFormat(string format, object[] args) {
        ErrorFormat(format, args);
    }

    public void FatalFormat(string format, object arg0) {
        ErrorFormat(format, arg0);
    }

    public void FatalFormat(string format, object arg0, object arg1) {
        ErrorFormat(format, arg0, arg1);
    }

    public void FatalFormat(string format, object arg0, object arg1, object arg2) {
        ErrorFormat(format, arg0, arg1, arg2);
    }

    public void FatalFormat(System.IFormatProvider provider, string format, object[] args) {
        ErrorFormat(format, args);
    }
}
